<?php
class myrouter {
	private $con;
	private $act;
	public function __construct( $request ){
		//----路由的实现--------
		$this->con = $request->r('con');
		if($this->con != ''){
			if(!preg_match("/^[a-z0-9_]+$/i",$this->con)){
				die('invalid con');
			}
		}else {
			$this->con = 'index';
		}

		$this->act = $request->r('act');
		if($this->act != ''){
			if(!preg_match("/^[a-z0-9_]+$/i",$this->con)){
				die('invalid act name ');
			}
		}else {
			$this->act = 'default';
		}

		if($this->con == 'index' && $this->act == 'view'){
			die('invalid act name');
		}
	}

	public function getViewFile(){
		if ($this->act == ''){
			return (MYLIB_VIEW_PATH.$this->con.'default.view.php');
		}else {
			return (MYLIB_VIEW_PATH.$this->con.$this->act.'.view.php');
		}
	}
		
	public function setCon( $con ){
		$this->con = $con;
	}
	
	public function setAct( $act ){
		$this->act = $act;
	}
	
	public function getControllerFile(){
		if(IS_ADMIN_SYS){
			$extFile =  MYLIB_CONTROLLER_PATH.$this->getCon().'ext.con.php';
			if(file_exists($extFile)){
				return $extFile;
			}
		}
			return MYLIB_CONTROLLER_PATH.$this->getCon().'.con.php';
	}

	public function getCon(){
		return $this->con;
	}

	public function getAct(){
		return $this->act;
	}
	
	public function getControllerName(){
		return $this->getCon().'Con';
	}
	
	public function getActName(){
		return $this->getAct().'Action';
	}
}




?>